package com.example.study_thread.a_collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;

public class Demo2Collections {
    public static void main(String[] args) {
        ArrayList<Person> person = new ArrayList<>();
        person.add(new Person("张三", 18));
        person.add(new Person("李四", 16));
        person.add(new Person("王五", 20));

        //        按照指定规则进行排序
        Collections.sort(person, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o1.getAge() - o2.getAge();
            }
        });

        System.out.println(person);
    }
}
